﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace MinhTuan
{
   public class Comment
   {
       public int Id { get; set; }
       public int Product_Id { get; set; }
       public String UserName { get; set; }
       public String Email { get; set; }
       public String Title { get; set; }
       public String Detail { get; set; }
       public DateTime Date_Comment{get;set; }
       public Comment() { 
       
       }
       #region method
       public static DataTable GetComment(int product_Id)
       {
           DataTable tbl = new DataTable();
           try
           {
               Access.InitAccess();
               Access.mySqlCommand.CommandText = "Sp_Comment_GetAll";
               Access.mySqlCommand.Parameters.Add("@Product_Id", SqlDbType.Int).Value = product_Id;
               SqlDataAdapter da = new SqlDataAdapter(Access.mySqlCommand);
               DataSet ds = new DataSet();
               da.Fill(ds);
               tbl = ds.Tables[0];
               Access.ClosedAccess();
               return tbl;
           }
           catch {
               Access.ClosedAccess();
               return tbl;
           }

       
       }
       public static Boolean Save(Comment comment)
       {
           try
           {
               Access.InitAccess();
               Access.mySqlCommand.CommandText = "Sp_Comment_AddNew";
               Access.mySqlCommand.Parameters.Add("Product_Id", SqlDbType.Int).Value = comment.Product_Id;
               Access.mySqlCommand.Parameters.Add("Comment_Name", SqlDbType.NVarChar).Value = comment.UserName;
               Access.mySqlCommand.Parameters.Add("Comment_Title", SqlDbType.NVarChar).Value = comment.Title;
               Access.mySqlCommand.Parameters.Add("Comment_Email", SqlDbType.NVarChar).Value = comment.Email;
               Access.mySqlCommand.Parameters.Add("Comment_Detail", SqlDbType.NVarChar).Value = comment.Detail;
               Access.mySqlCommand.Parameters.Add("Comment_Date", SqlDbType.DateTime).Value = DateTime.Now;
               int result = 0;
               result = Convert.ToInt16(Access.mySqlCommand.ExecuteNonQuery());
               Access.ClosedAccess();
               if (result > 0) return true;
               else return false;

           }
           catch {
               Access.ClosedAccess();
               return false;
           }
       }
       #endregion
   }
}
